From 53f23f8ae9b2b23c1f917fae0b25049552643b45 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 29 May 2019 05:48:38 +0200 Subject: [PATCH] rendernodeparser: Handle empty Cairo nodes Cairo nodes can contain a NULL surface if they have never been drawn to. Make this the default Cairo node. --- gsk/gskrendernodeparser.c | 58 +++++++++--------- testsuite/gsk/compare/empty-cairo.png | Bin 153 -> 1340 bytes testsuite/gsk/nodeparser/empty-cairo.ref.node | 2 - 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/gsk/gskrendernodeparser.c b/gsk/gskrendernodeparser.c index 6dc1d19448..4cdf70f630 100644 --- a/gsk/gskrendernodeparser.c +++ b/gsk/gskrendernodeparser.c @@ -1065,32 +1065,31 @@ parse_cairo_node (GtkCssParser *parser) { "script", parse_script, clear_surface, &surface } }; GskRenderNode *node; - cairo_t *cr; parse_declarations (parser, declarations, G_N_ELEMENTS(declarations)); node = gsk_cairo_node_new (&bounds); - cr = gsk_cairo_node_get_draw_context (node); - if (surface != NULL) { + cairo_t *cr = gsk_cairo_node_get_draw_context (node); cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); + cairo_destroy (cr); } else if (pixels != NULL) { + cairo_t *cr = gsk_cairo_node_get_draw_context (node); surface = gdk_texture_download_surface (pixels); cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); + cairo_destroy (cr); } else { - gdk_cairo_set_source_rgba (cr, &GDK_RGBA ("FF00CC")); - cairo_paint (cr); + /* do nothing */ } - cairo_destroy (cr); g_clear_object (&pixels); g_clear_pointer (&surface, cairo_surface_destroy); @@ -2380,36 +2379,39 @@ render_node_print (Printer *p, start_node (p, "cairo"); append_rect_param (p, "bounds", &node->bounds); - array = g_byte_array_new (); - cairo_surface_write_to_png_stream (surface, cairo_write_array, array); - b64 = g_base64_encode (array->data, array->len); + if (surface != NULL) + { + array = g_byte_array_new (); + cairo_surface_write_to_png_stream (surface, cairo_write_array, array); + b64 = g_base64_encode (array->data, array->len); - _indent (p); - g_string_append_printf (p->str, "pixels: url(\"data:image/png;base64,%s\");\n", b64); + _indent (p); + g_string_append_printf (p->str, "pixels: url(\"data:image/png;base64,%s\");\n", b64); - g_free (b64); - g_byte_array_free (array, TRUE); + g_free (b64); + g_byte_array_free (array, TRUE); #ifdef CAIRO_HAS_SCRIPT_SURFACE - if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_RECORDING) - { - cairo_device_t *script; + if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_RECORDING) + { + cairo_device_t *script; - array = g_byte_array_new (); - script = cairo_script_create_for_stream (cairo_write_array, array); + array = g_byte_array_new (); + script = cairo_script_create_for_stream (cairo_write_array, array); - if (cairo_script_from_recording_surface (script, surface) == CAIRO_STATUS_SUCCESS) - { - b64 = g_base64_encode (array->data, array->len); - _indent (p); - g_string_append_printf (p->str, "script: url(\"data:;base64,%s\");\n", b64); - g_free (b64); - } + if (cairo_script_from_recording_surface (script, surface) == CAIRO_STATUS_SUCCESS) + { + b64 = g_base64_encode (array->data, array->len); + _indent (p); + g_string_append_printf (p->str, "script: url(\"data:;base64,%s\");\n", b64); + g_free (b64); + } - cairo_device_destroy (script); - g_byte_array_free (array, TRUE); - } + cairo_device_destroy (script); + g_byte_array_free (array, TRUE); + } #endif + } end_node (p); } diff --git a/testsuite/gsk/compare/empty-cairo.png b/testsuite/gsk/compare/empty-cairo.png index 3a032a391ba59878cabf3e55f84ac5700bf00ff0..b4dff4c12fce4c886df27491d834376957aca2e1 100644 GIT binary patch delta 1332 zcmV-41ESaechcOY}sdU*@Gtu2Ki&+@L2`R&q&-2-zw)5BgxjS{=B=GLNzv}bVye`i~3l~?qOg>I%Q9bsD_WCZ@XsHQrdb*lnYR5Cac3w9JiV+maY(ZW~Hil_r}5pDqb(8psLEe8)oDZ(jc3EWvXp zjAVisVa8K+uZBOZPeOC9ZBFFVoh!t}Yu6x*MQ%MY3V%Roo}B8=FS)DnuVsN15Y(OK zgasB~FNv!3*jutWi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